using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	public static class CanvasExtension
	{
		public static Canvas Copy(this Canvas canvas, GameObject gameObjectToAddTo)
		{
			Canvas addComponent = gameObjectToAddTo.GetAddComponent<Canvas>();
			RectTransform component = canvas.GetComponent<RectTransform>();
			RectTransform component2 = addComponent.GetComponent<RectTransform>();
			component2.position = component.position;
			component2.sizeDelta = component.sizeDelta;
			component2.anchorMin = component.anchorMin;
			component2.anchorMax = component.anchorMax;
			component2.pivot = component.pivot;
			component2.rotation = component.rotation;
			component2.localScale = component.localScale;
			addComponent.gameObject.GetAddComponent<GraphicRaycaster>();
			CanvasScaler component3 = canvas.GetComponent<CanvasScaler>();
			if (component3 != null)
			{
				CanvasScaler addComponent2 = addComponent.gameObject.GetAddComponent<CanvasScaler>();
				addComponent2.uiScaleMode = component3.uiScaleMode;
				addComponent2.referenceResolution = component3.referenceResolution;
				addComponent2.screenMatchMode = component3.screenMatchMode;
				addComponent2.matchWidthOrHeight = component3.matchWidthOrHeight;
				addComponent2.referencePixelsPerUnit = component3.referencePixelsPerUnit;
			}
			addComponent.gameObject.GetAddComponent<MaterialUIScaler>();
			addComponent.renderMode = canvas.renderMode;
			return addComponent;
		}

		public static void CopySettingsToOtherCanvas(this Canvas canvas, Canvas otherCanvas)
		{
			RectTransform component = canvas.GetComponent<RectTransform>();
			RectTransform component2 = otherCanvas.GetComponent<RectTransform>();
			component2.position = component.position;
			component2.sizeDelta = component.sizeDelta;
			component2.anchorMin = component.anchorMin;
			component2.anchorMax = component.anchorMax;
			component2.pivot = component.pivot;
			component2.rotation = component.rotation;
			component2.localScale = component.localScale;
			otherCanvas.gameObject.GetAddComponent<GraphicRaycaster>();
			CanvasScaler component3 = canvas.GetComponent<CanvasScaler>();
			if (component3 != null)
			{
				CanvasScaler addComponent = otherCanvas.gameObject.GetAddComponent<CanvasScaler>();
				addComponent.uiScaleMode = component3.uiScaleMode;
				addComponent.referenceResolution = component3.referenceResolution;
				addComponent.screenMatchMode = component3.screenMatchMode;
				addComponent.matchWidthOrHeight = component3.matchWidthOrHeight;
				addComponent.referencePixelsPerUnit = component3.referencePixelsPerUnit;
			}
			otherCanvas.gameObject.GetAddComponent<MaterialUIScaler>();
			otherCanvas.renderMode = canvas.renderMode;
		}
	}
}
